package ants.bot;

import java.util.Comparator;

import ants.map.scent.CombatScentMap;
import ants.map.tile.AntTile;

public class WarOptionComparator implements Comparator<WarOption> {

	private int threatAlertScent;
	private int threatCombinedScent;
	private int threatDangerScent;

	private int compare(int scentA, int scentB, int threatScent) {

		if (scentA >= threatScent) {

			if (scentB >= threatScent) {

				/* A greater, B greater */
				return scentB - scentA;

			} else {

				/* A greater, B less */
				return -1;

			}

		} else {

			if (scentB >= threatScent) {

				/* A less, B greater */
				return 1;

			} else {

				/* A less, B less */
				return scentA - scentB;

			}

		}

	}

	@Override
	public int compare(WarOption optionA, WarOption optionB) {

		int cmp = compare(optionA.getCombinedScent(), optionB.getCombinedScent(),
				threatCombinedScent);

		if (cmp == 0)
			cmp = compare(optionA.getDangerScent(), optionB.getDangerScent(),
					threatDangerScent);

		if (cmp == 0)
			cmp = compare(optionA.getAlertScent(), optionB.getAlertScent(),
					threatAlertScent);

		return cmp;
	}

	public int getThreatAlertScent() {
		return threatAlertScent;
	}

	public int getThreatCombinedScent() {
		return threatCombinedScent;
	}

	public int getThreatDangerScent() {
		return threatDangerScent;
	}

	public void setAnt(AntTile ant) {

		threatAlertScent = CombatScentMap.BASE_SOURCE;
		if (ant.getAlertThreat() > 1) {
			threatAlertScent /= ant.getAlertThreat();
		}

		threatDangerScent = CombatScentMap.BASE_SOURCE;
		if (ant.getDangerThreat() > 1) {
			threatDangerScent /= ant.getDangerThreat();
		}

		threatCombinedScent = threatAlertScent + threatDangerScent;
	}

}
